package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.JobDAO;
import com.yang.doctorrecruitment.dto.ReleaseJob;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class GetJobReleaseByJobIDAction extends ActionSupport {
    private JSON json;


    public String GetJobReleaseByJobID(){
        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        String JobID=request.getParameter("JobID");

        ReleaseJob job= JobDAO.getReleseJobByJobID(JobID);
        JSONObject Ojson=new JSONObject();
        Ojson.put("JobName",job.getJobName());
        Ojson.put("JobAddress",job.getJobAddress());
        Ojson.put("JobNum",job.getJobNum());
        Ojson.put("JobRequire",job.getJobRequire());
        Ojson.put("JobSalary",job.getJobSalary());
        Ojson.put("UserID",job.getUserID());
        Ojson.put("JobDuty",job.getJobDuty());
        session.put("currentID",JobID);
        json=Ojson;
        return SUCCESS;
    }


    public String DeleteReleaseJobByJobID(){
        ActionContext ac=ActionContext.getContext();
        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        System.out.println("还没拿到jobID------");
        String JobID=request.getParameter("JobID");
        System.out.println(JobID+"------");
        JSONObject Ojson=new JSONObject();
        boolean res=JobDAO.deleteJob(JobID);
        if(res){
            System.out.println("删除成功------");
            Ojson.put("result","success");
            json=Ojson;
            return SUCCESS;
        }else{

            Ojson.put("result","failed");
            json=Ojson;
            return ERROR;
        }


    }
    public JSON getJson() {
        return json;
    }

    public void setJson(JSON json) {
        this.json = json;
    }
}
